package com.qianyu.project.service.handler;

import com.alibaba.fastjson.JSON;
import com.qianyu.project.core.annotation.FlowHandler;
import com.qianyu.project.core.bean.FormAudit;
import com.qianyu.project.core.context.handler.FlowFinishedHandler;
import com.qianyu.project.entity.TenderPurchasePlan;
import com.qianyu.project.service.ITenderPurchasePlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author gs
 * @date create in 2021/2/2 5:58
 */
@Component
@FlowHandler("tender_purchase_plan")
public class TenderPurchasePlanHandler implements FlowFinishedHandler {

    @Autowired
    private ITenderPurchasePlanService tenderPurchasePlanService;

    @Override
    public void postAllowHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit , 3);
    }

    @Override
    public void postRefuseHandle(String jsonForm, FormAudit formAudit) {
        this.commonUpdate(jsonForm, formAudit , 2);
    }

    /**
     * description: 通用更新的方法 <br/>
     * author: gs   <br/>
     * date: 2021/2/2 <br/>
     * params: [jsonForm, formAudit] <br/>
     * return: void
     */
    private void commonUpdate(String jsonForm,FormAudit formAudit, Integer approveStatus) {
        TenderPurchasePlan tenderPurchasePlan = JSON.parseObject(jsonForm,TenderPurchasePlan.class);
        tenderPurchasePlan.setApproveStatus(approveStatus);
        if (approveStatus == 3) {
            tenderPurchasePlan.setStatus("2");
        }
        tenderPurchasePlanService.updateById(tenderPurchasePlan);
    }
}
